﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class UIManagerScript : MonoBehaviour {

	//panele
	public GameObject panelMain;
	public GameObject panelStart;
	public GameObject panelHowToPlay;
	public GameObject panelAbout;
	public GameObject panelWin;
	public GameObject panelLose;

	//przyciski dla poziomów trudności
	public GameObject[] buttonsDifficultyLevel;

	//poziom trudności
	public int difficultyLevel;

	public static bool enabledWin = false;
	public static bool enabledLose = false;
	void Start()
	{
		GoBack ();
		difficultyLevel = -1;
		foreach (GameObject element in buttonsDifficultyLevel) {
			element.GetComponent<Button> ().interactable = true;
		}
	}

	void Update()
	{
		if (enabledWin) {
			Win ();
		}
		if (enabledLose) {
			Lose ();
		}

	}
	//panel StartGame
	public void StartGame()
	{
		panelMain.SetActive (false);
		panelStart.SetActive (true);
	}

	public void ChangeDifficultyLevel(int difficulty){
		difficultyLevel = difficulty;

		foreach (GameObject element in buttonsDifficultyLevel) {
			element.GetComponent<Button> ().interactable = true;
		}
		buttonsDifficultyLevel [difficulty].GetComponent<Button> ().interactable = false;
	}

	public void StartLevel1()
	{
		if (difficultyLevel != -1) {
			switch(difficultyLevel) {
			case 0: Spawner.maxCharacterCounter = 60; TargetSpawner.targetNumber = 4; break;
			case 1: Spawner.maxCharacterCounter = 100; TargetSpawner.targetNumber = 5; break;
			case 2: Spawner.maxCharacterCounter = 120; TargetSpawner.targetNumber = 6; break;
			}
			Application.LoadLevel ("Level1");

		}
	}

	//panel HowToPlay
	public void HowToPlay()
	{
		panelMain.SetActive (false);
		panelHowToPlay.SetActive (true);
	}

	//panel About
	public void About()
	{
		panelMain.SetActive (false);
		panelAbout.SetActive (true);
	}


	//przycisk GoBack
	public void GoBack(){
		//panel Main aktywny
		panelMain.SetActive (true);

		//resetowanie poziomów trudnośći
		foreach (GameObject element in buttonsDifficultyLevel) {
			element.GetComponent<Button> ().interactable = true;
		}
		difficultyLevel = -1;

		//wszystkie panale nieaktywne
		panelStart.SetActive (false);
		panelHowToPlay.SetActive (false);
		panelAbout.SetActive (false);
		panelWin.SetActive (false);
		panelLose.SetActive (false);
	}

	//panel Win
	public void Win()
	{
		enabledWin = false;
		panelMain.SetActive (false);
		panelWin.SetActive (true);
		panelWin.GetComponentInChildren<Text>().text = "You WIN!!! \n points: "+ (Points.points).ToString();

	}

	//panel Lose
	public void Lose()
	{
		enabledLose = false;
		panelMain.SetActive (false);
		panelLose.SetActive (true);
		panelLose.GetComponentInChildren<Text>().text = "You WIN!!! \n points: "+ (Points.points).ToString();
	}
}
